package com.jiangnan.utils;

/**
 *
 * 十六进制转化工具类
 * @author chenliang
 * @email wschenliang@aliyun.com
 */
public class HexUtil {

    private final static char[] MD5_HEX = {
            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
    };
    public static String byteArrayToHexString(byte[] b, String gap) {
        String[] array = byteArray2HexStringArray(b);
        return StringUtils.toString(array, gap);
    }

    public static String[] byteArray2HexStringArray(byte[] b) {
        String[] s = new String[b.length];
        for (int i = 0; i < b.length; i++) {
            int temp = b[i];
            if (temp < 0) {
                temp = 256 + temp;
            }
            s[i] = MD5_HEX[temp >>> 4] + "" + MD5_HEX[temp & 0x0f];
        }
        return s;
    }

}
